/*
 * =====================================================================================
 *
 *       Filename:  evaluate.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2015/05/17 21时37分08秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Liu Yi (), swliuyi@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#include <fstream>
#include <iostream>
#include "hmm.h"

using namespace std;
int main(int argc, char* argv[])
{
    Hmm hmm;
    if (argc<3) {
        cerr << "USAGE: evalauate test answer" << endl;
        return 1;
    }
    ifstream test(argv[1]);
    ifstream answer(argv[2]);


    vector<vector<pair<unsigned long, unsigned long> > *> testSequences;
    vector<vector<pair<unsigned long, unsigned long> > *> answerSequences;

    hmm.preProcess(test, testSequences, 0);
    hmm.preProcess(answer, answerSequences, 0);


    double accuracy = 0;
    double recall = 0;
    double count = 0;

    double rr = 0, rw = 0, wr = 0, ww = 0;

    unsigned int o = hmm.getId("o");
    unsigned int ns = hmm.getId("ns");
    unsigned int nsb = hmm.getId("nsb");
    unsigned int nsm = hmm.getId("nsm");
    unsigned int nsd = hmm.getId("nsd");
    unsigned int nr = hmm.getId("nr");
    unsigned int nt = hmm.getId("nt");
    unsigned int ntb = hmm.getId("ntb");
    unsigned int ntm = hmm.getId("ntm");
    unsigned int ntd = hmm.getId("ntd");

    //cout<<o<<endl;

    for( unsigned i = 0; i < answerSequences.size() ; i++ )
    {
        for( unsigned j = 0 ; j < (*answerSequences[i]).size() ; j++ )
        {
            unsigned int ans = (*answerSequences[i])[j].second;
            unsigned int tst;
            if( testSequences.size() > i && (*testSequences[i]).size() > j )
            {
                tst = (*testSequences[i])[j].second;
            }
            else
            {
                cout<<i<<" "<<j<<endl;
                continue;
            }
            if( tst == ans && ans != o)
            {
                rr += 1;
            }
            if( ans != o )
            {
                recall += 1;
            }
            if( tst != o )
            {
                accuracy += 1;
            }
        }
    }
    cout<<rr<<endl;
    cout<<recall<<endl;
    cout<<accuracy<<endl;
    cout<<"R "<<rr/recall<<endl;
    cout<<"P "<<rr/accuracy<<endl;
}
